import type { CommonState, PageReq, PageRes } from '../common/commonApi'
import type { AppRoleQuery } from './appRoleApi'
import { useApi } from '@/composables/useApi'

/**
 * 系统设置
 */
export interface SysSettings {
  /** 主键 */
  id?: number
  /** 名称 */
  name?: string
  /** 编码 */
  code?: string
  /** 状态 */
  state?: CommonState
  /** 设置定义 */
  settingsSchema?: string
  /** 设置内容 */
  settingsData?: string
  /** 最近更新事件 */
  updateTime?: string
}

export interface SysSettingsQuery extends PageReq {
  /** 主键 */
  id?: number
  /** 名称 */
  name?: string
  /** 编码 */
  code?: string
  /** 状态 */
  state?: CommonState
}

export interface SysSettingsDataModifyCmd {
  /** 主键 */
  id?: number
  /** 设置内容 */
  settingsData?: string
}

const basePath = '/system/settings'
export const sysSettingsApi = {
  queryPage: useApi<AppRoleQuery, PageRes<SysSettings>>(`${basePath}/page`).get,
  findDetail: async (id: number) => useApi<any, SysSettings>(`${basePath}/${id}`).get(),
  create: useApi<SysSettings, SysSettings>(`${basePath}`).post,
  modify: useApi<SysSettings, SysSettings>(`${basePath}`).patch,
  remove: async (id: number) => useApi<null, SysSettings>(`${basePath}/${id}`).remove(),
  modifyData: useApi<SysSettingsDataModifyCmd, any>(`${basePath}/data`).put,
}
